﻿using Md.Api.Model;
using Md.Api.Model.Web.MdUser.Request;
using Md.Api.Service.Web.MdUser;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Web;
/// <summary>
/// PC用户管理
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/web/user")]
public class MdUserWebController : ControllerBase
{
    /// <summary>
    /// 发送邮箱验证码服务
    /// </summary>
    public SendEmailVerificationCodeService sendEmailVerificationCodeService { get; set; }
    /// <summary>
    /// 发送邮箱验证码
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("sendEmailVerificationCode"), HttpPost, AllowAnonymous]
    public async Task<ResponseMessageModel> SendEmailVerificationCode([FromBody] RequestSendEmailVerificationCodeModel model)
    {
        return await Task.Run(() => sendEmailVerificationCodeService.Execute(model));
    }

    /// <summary>
    /// 用户登录服务
    /// </summary>
    public LoginMdUserWebService loginMdUserWebService { get; set; }
    /// <summary>
    /// 用户登录
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("login"), HttpPost, AllowAnonymous]
    public async Task<ResponseMessageModel> loginMdUser([FromBody] RequestLoginMdUserWebModel model)
    {
        return await Task.Run(() => loginMdUserWebService.Execute(model));
    }

    /// <summary>
    /// 用户注册服务
    /// </summary>
    public RegisterMdUserWebService registerMdUserWebService { get; set; }
    /// <summary>
    /// 用户注册
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("register"), HttpPost, AllowAnonymous]
    public async Task<ResponseMessageModel> RegisterMdUser([FromBody] RequestRegisterMdUserWebModel model)
    {
        return await Task.Run(() => registerMdUserWebService.Execute(model));
    }

    /// <summary>
    /// 通过用户编号更新用户密码服务
    /// </summary>
    public ResetMdUserPwdWebService resetMdUserPwdWebService { get; set; }
    /// <summary>
    /// 通过用户编号更新用户密码
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("resetPwd"), HttpPost]
    public async Task<ResponseMessageModel> ResetMdUserPwd([FromBody] RequestResetMdUserPwdWebModel model)
    {
        return await Task.Run(() => resetMdUserPwdWebService.Execute(model));
    }

    /// <summary>
    /// 通过用户编号更新用户服务
    /// </summary>
    public UpdateMdUserByUserIdWebService updateMdUserByUserIdWebService { get; set; }
    /// <summary>
    /// 通过用户编号更新用户
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateMdUserByUserIdWeb([FromBody] RequestUpdateMdUserByUserIdWebModel model)
    {
        return await Task.Run(() => updateMdUserByUserIdWebService.Execute(model));
    }

    /// <summary>
    /// 通过用户编号获取用户信息服务
    /// </summary>
    public GetMdUserByUserIdWebService getMdUserByUserIdWebService { get; set; }
    /// <summary>
    /// 通过用户编号获取用户信息
    /// </summary>
    /// <param name="userId">用户编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{userId}")]
    public async Task<ResponseMessageModel> GetMdUserByUserId(long userId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestWebGetMdUserByUserIdModel();

        model.UserId = userId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getMdUserByUserIdWebService.Execute(model));
    }
}

